<template>
    <div>
    <Modal :title="modalTitle" v-model="modalVisible" :mask-closable='false' :width="600" :styles="{top: '100px'}">
        <Form ref="form" :model="form" :label-width="70" >
            <FormItem label="学历条件" prop="stuId">
                <Select v-model="form.stuId" placeholder="选择学历条件" clearable style="width: 450px">
                    <Option v-for="item in stuItemList" :value="item.id" :key="item.id">{{item.conditionName}}</Option>
                </Select>
            </FormItem>
            <FormItem label="工作条件" prop="workId">
                <Select v-model="form.workId" placeholder="选择工作条件" clearable style="width: 450px">
                    <Option v-for="item in workItemList" :value="item.id" :key="item.id">{{item.conditionName}}</Option>
                </Select>
            </FormItem>
            <FormItem label="排序" prop="sortOrder">
                <InputNumber v-model="form.sortOrder" style="width:450px"/>
            </FormItem>
        </Form>
        <div slot="footer">
            <Button type="text" @click="cancelUser">取消</Button>
            <Button type="primary" :loading="submitLoading" @click="handelSubmit">提交</Button>
        </div>
    </Modal>
    </div>
</template>

<script>
    import {addItem, selectItem} from "@/api/bus";
    export default {
        name: "itemDrawer",
        components: {

        },
        data() {
            return {
                type:0,
                errorPass: "",
                deptLoading: false,
                modalTitle: "添加条件",
                submitLoading: false,
                modalVisible: false,
                stuItemList: [],
                workItemList: [],
                form: {
                    examinationId:"",
                    stuId: "",
                    workId: "",
                    itemIds: "",
                    sortOrder: 0
                }
            }
        },
        methods: {
            init() {

            },
            showDrawer(params) {
                this.modalVisible = true;
                if (params.examinationId) {
                    this.type = 1;
                    this.modalTitle = "添加报考条件";
                    this.form.examinationId = params.examinationId;
                    this.getData();
                }
            },
            getData(){
                selectItem(this.searchForm).then(res => {
                    this.loading = false;
                    if (res.status === true) {
                        this.stuItemList = res.data.stuItemList;
                        this.workItemList = res.data.workItemList;
                    }
                });
            },
            cancelUser() {
                this.modalVisible = false;
            },
            handelSubmit() {
                if(this.form.stuId == "undefined" || this.form.stuId == undefined){
                    this.form.stuId = ''
                }
                if(this.form.workId == "undefined" || this.form.workId == undefined){
                    this.form.workId = ''
                }
                if(this.form.stuId == "" && this.form.workId == ""){
                    this.$Message.error("必须选择一个条件");
                    return;
                }
                if(this.form.stuId == ""){
                    this.form.itemIds = this.form.workId
                }
                if(this.form.workId == ""){
                    this.form.itemIds = this.form.stuId
                }
                if(this.form.stuId != "" && this.form.workId != ""){
                    this.form.itemIds = this.form.stuId + "," + this.form.workId
                }
                this.$refs.form.validate(valid => {
                    if (valid) {
                        this.submitLoading = true;
                        // 添加 避免编辑后传入id等数据 记得删除
                        addItem(this.form).then(res => {
                            this.submitLoading = false;
                            if (res.status === true) {
                                this.$Message.success("添加成功");
                                this.$parent.getDataList();
                                this.$parent.resetApplyItem();
                                this.modalVisible = false;
                            }
                        });
                    }
                });
            }
        },
        mounted() {

        }
    }
</script>

<style>

</style>